using JQueryControlToolkit.Controls;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web.UI;
namespace JQueryControlToolkit
{
	[ParseChildren(true, "Elements"), PersistChildren(true)]
	public class Container<T> : Control, JSArray, IEnumerable<JSObject>, IEnumerable, JSObject where T : Control, JSObject
	{
		public Control Owner
		{
			get;
			set;
		}
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ContainerChildrenCollection<T> Elements
		{
			get;
			private set;
		}
		public override string ID
		{
			get
			{
				if (base.ID == null)
				{
					this.ID = this.Owner.ID + "_Container";
				}
				return base.ID;
			}
			set
			{
				base.ID = value;
			}
		}
		public override Control NamingContainer
		{
			get
			{
				return this.Owner.NamingContainer;
			}
		}
		public Container() : this(null)
		{
		}
		public Container(Control owner)
		{
			this.Owner = owner;
			this.Elements = new ContainerChildrenCollection<T>(this);
		}
		public IEnumerator<JSObject> GetEnumerator()
		{
			foreach (T current in this.Elements)
			{
				yield return current;
			}
			yield break;
		}
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}
		public string ToScript()
		{
			return Extensions.ToScript(this);
		}
		public void ToScript(TextWriter toScript)
		{
			bool isFirst = true;
			toScript.Write("{ ");
			foreach (JSObject item in this)
			{
				if (isFirst)
				{
					isFirst = false;
				}
				else
				{
					toScript.Write(", ");
				}
				item.ToScript(toScript);
			}
			toScript.Write(" }");
		}
	}
}
